
const _interopRequireDefault = require('@babel/runtime/helpers/interopRequireDefault');

exports.__esModule = true;
exports.default = void 0;

const _extends2 = _interopRequireDefault(require('@babel/runtime/helpers/extends'));

const _babelHelperVueJsxMergeProps = _interopRequireDefault(require('@vue/babel-helper-vue-jsx-merge-props'));

const _utils = require('../utils');

const _functional = require('../utils/functional');

const _router = require('../utils/router');

const _shared = require('./shared');

const _icon = _interopRequireDefault(require('../icon'));

// Utils
// Components
const _createNamespace = (0, _utils.createNamespace)('cell');
const createComponent = _createNamespace[0];
const bem = _createNamespace[1];

function Cell(h, props, slots, ctx) {
  const { icon } = props;
  const { size } = props;
  const { title } = props;
  const { label } = props;
  const { value } = props;
  const { isLink } = props;
  const showTitle = slots.title || (0, _utils.isDef)(title);

  function Label() {
    const showLabel = slots.label || (0, _utils.isDef)(label);

    if (showLabel) {
      return h('div', {
        class: [bem('label'), props.labelClass],
      }, [slots.label ? slots.label() : label]);
    }
  }

  function Title() {
    if (showTitle) {
      return h('div', {
        class: [bem('title'), props.titleClass],
        style: props.titleStyle,
      }, [slots.title ? slots.title() : h('span', [title]), Label()]);
    }
  }

  function Value() {
    const showValue = slots.default || (0, _utils.isDef)(value);

    if (showValue) {
      return h('div', {
        class: [bem('value', {
          alone: !showTitle,
        }), props.valueClass],
      }, [slots.default ? slots.default() : h('span', [value])]);
    }
  }

  function LeftIcon() {
    if (slots.icon) {
      return slots.icon();
    }

    if (icon) {
      return h(_icon.default, {
        class: bem('left-icon'),
        attrs: {
          name: icon,
          classPrefix: props.iconPrefix,
        },
      });
    }
  }

  function RightIcon() {
    const rightIconSlot = slots['right-icon'];

    if (rightIconSlot) {
      return rightIconSlot();
    }

    if (isLink) {
      const { arrowDirection } = props;
      return h(_icon.default, {
        class: bem('right-icon'),
        attrs: {
          name: arrowDirection ? `arrow-${arrowDirection}` : 'arrow',
        },
      });
    }
  }

  function onClick(event) {
    (0, _functional.emit)(ctx, 'click', event);
    (0, _router.functionalRoute)(ctx);
  }

  const clickable = isLink || props.clickable;
  const classes = {
    clickable,
    center: props.center,
    required: props.required,
    borderless: !props.border,
  };

  if (size) {
    classes[size] = size;
  }

  return h('div', (0, _babelHelperVueJsxMergeProps.default)([{
    class: bem(classes),
    attrs: {
      role: clickable ? 'button' : null,
      tabindex: clickable ? 0 : null,
    },
    on: {
      click: onClick,
    },
  }, (0, _functional.inherit)(ctx)]), [LeftIcon(), Title(), Value(), RightIcon(), slots.extra == null ? void 0 : slots.extra()]);
}

Cell.props = (0, _extends2.default)({}, _shared.cellProps, {}, _router.routeProps);

const _default = createComponent(Cell);

exports.default = _default;
